home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d22 / diskedit.arc / DISKS.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-09-06  |  2.2 KB  |  70 lines

  1. /* disks.c - interface to IBM ROM BIOS disk routines */
  2. /* lrs 2/13/89 */
  3.  
  4. #include <bios.h>
  5. #include <dos.h>
  6. #include "disks.h"
  7.  
  8. void InitDisks()
  9.   { /* ROM BIOS "Reset Disks" command */
  10.   union REGS reg;
  11.   reg.x.ax = 0;
  12.   int86(0x13,®,®);
  13.   }    /* InitDisks */
  14. /*-----------------------------------------------------------------------*/
  15. void GetDiskParams(int drive, int* maxcyl, int* maxhead, int* maxsec)
  16.   { /* get size of disk */
  17.     /* (note: this (and the rest) assumes 512 byte sectors */
  18.   union REGS reg;
  19.   reg.h.ah = 8;
  20.   reg.h.dl = drive;
  21.   int86(0x13,®,®);
  22.   *maxcyl = reg.h.ch + ((reg.h.cl & 0xC0) << 2);
  23.   *maxhead = reg.h.dh;
  24.   *maxsec = reg.h.cl & 0x3F;
  25.   }    /* GetDiskParameters */
  26. /*-----------------------------------------------------------------------*/
  27. int ReadSector (int drive, int cyl, int head, int sec, void far* buf)
  28.   { /* read a 512 byte sector from phys location on disk */
  29.     /* return TRUE if success */
  30.   union REGS reg;
  31.   struct SREGS sreg;
  32.  
  33.   int retry = 3;;
  34.   do {
  35.     reg.x.ax = 0x0201;
  36.     reg.x.bx = FP_OFF(buf);
  37.     sreg.es = FP_SEG(buf);
  38.     reg.h.ch = cyl & 0xFF;
  39.     /* top two bits (8 & 9) of cyl # hidden in bits 6 & 7 of sector */
  40.     reg.h.cl = sec | ((cyl >> 2) & 0xC0);
  41.     reg.h.dh = head;
  42.     reg.h.dl = drive;
  43.     int86x(0x13,®,®,&sreg);
  44.     } while ((reg.x.cflag) && (retry-- > 0));
  45.   return(reg.x.cflag == 0);
  46.   }   /* ReadSector */
  47. /*-----------------------------------------------------------------------*/
  48. int WriteSector (int drive, int cyl, int head, int sec, void far* buf)
  49.   { /* write memory block to specified physical sector on disk */
  50.     /* return TRUE if success */
  51.   union REGS reg;
  52.   struct SREGS sreg;
  53.   int retry = 3;
  54.  
  55.     do {
  56.       reg.x.ax = 0x0301;
  57.       reg.x.bx = FP_OFF(buf);    /* THIS MUST BE FIXED !!!! */
  58.       sreg.es = FP_SEG(buf);
  59.       reg.h.ch = cyl & 0xFF;
  60.       /* top two bits (8 & 9) of cyl # hidden in bits 6 & 7 of sector */
  61.       reg.h.cl = sec | ((cyl >> 2) & 0xC0);
  62.       reg.h.dh = head;
  63.       reg.h.dl = drive;
  64.       int86x(0x13,®,®,&sreg);
  65.       } while ((reg.x.cflag) && (retry-- > 0));
  66.     return(reg.x.cflag == 0);
  67.   }   /* WriteSector */
  68.  
  69. /*---- end of disks.c ----*/
  70.